function showAlert(date) {
    $.get('/Calendario/FindToDo?date='+escape(date), function(data) {
      var lista = eval(data);
      var resp = "";
      for(i in lista){
          resp += "<div class=\"task\">"
                 + "<div class=\"taskName\">" +  lista[i].descricao +  " <div ";
          if (lista[i].completed.toString().toLowerCase() == 'true'){
              resp += "class=\"completedStatus\">Status:  Completed</div>";
          } else {resp += "class=\"notCompletedStatus\">Status:  Not completed</div>"}
          
             
          resp += "</div><br/>" + "Data de Inicio: " + json2date(lista[i].dataInicio)
                 + " - Data de termino: " + json2date(lista[i].dataFim) 
                     + "<div class=\"completed\">"
                         + "<form action=\"UpdateTaskStatus\" name=\"taskStatus\" method=\"get\">"
                         + "<input type=\"radio\" name=\"status\" value=\"true." + lista[i].id + "\"/> Completed"
                         + "<input type=\"radio\" name=\"status\" value=\"false." + lista[i].id + "\"/> Not Completed"
                         + "<input type=\"submit\" value=\"Update status\">"
                         + "</form>"
                     + "</div>"
                     + "<div class=\"deleteOption\">"
                         + "<a href=\"DeleteTask?id=" + lista[i].id +  "\" class=\"deleteButton\">Delete this task</a>"
                         + "</form>"
                     + "</div>"
                 +"</div>";
      }
      if (lista == ''){
          resp += "<div class=\"task\">No Tasks on this date!</div>";
      }
      $("#taskList").html(resp);
      $("#shade").fadeIn("fast");
      $("#tasks").slideDown();
      //document.getElementById('shade').style.setProperty('display','block', null);
      //document.getElementById('tasks').style.setProperty('display','block', null);
    });
    loadMeetings(date);
}
function loadMeetings(date){
    $.get('/Calendario/FindMeetings?date='+escape(date), function(data) {
      var lista = eval(data);
      var resp = "";
      
      for(i in lista){
          resp += "<div class=\"task\">"+ lista[i].nomeReuniao + " - Data da reunião: " + json2date(lista[i].dataInicio) +"</div>";
      }
      if (lista == ''){
          resp += "<div class=\"task\">No Meetings on this date!</div>";
      }
      $("#meetingsList").html(resp);
      $("#shade").fadeIn("fast");
      $("#tasks").slideDown();
//      document.getElementById('shade').style.setProperty('display','block', null);
//      document.getElementById('tasks').style.setProperty('display','block', null);
    });
}

function hideAlert() {
    $("#shade").fadeOut("fast");
    $("#tasks").slideUp();
    $("#form").slideUp();
    $("#formReuniao").slideUp();
    $("#formCategory").slideUp();
    //document.getElementById('shade').style.setProperty('display','none', null);
    //document.getElementById('form').style.setProperty('display','none', null);
    //document.getElementById('formReuniao').style.setProperty('display','none', null);
    //document.getElementById('formCategory').style.setProperty('display','none', null);
}

function checkDate(obj) {
    obj = document.getElementById(obj);
    if (!isDate(obj.value)) {
        obj.style.setProperty('background','#FBBBB9',null);
        document.getElementById("submit").disabled = true;
        document.getElementById("submitMeeting").disabled = true;
    } else {
        obj.style.setProperty('background','white',null);
        document.getElementById("submit").disabled = false;
        document.getElementById("submitMeeting").disabled = false;
    }
}

function checkNull(obj){
    obj = document.getElementById(obj);
    if(obj.value == ''){
        obj.style.setProperty('background','#FBBBB9',null);
        document.getElementById("submitCategory").disabled = true;
    } else{
        obj.style.setProperty('background','white',null);
        document.getElementById("submitCategory").disabled = false;
    }
}

function createToDo() {
    $("#shade").fadeIn("fast");
    $("#form").slideDown();
  //document.getElementById('shade').style.setProperty('display','block', null);
  //document.getElementById('form').style.setProperty('display','block', null);
}

function createNewMeeting() {
    $("#shade").fadeIn("fast");
    $("#formReuniao").slideDown();
  //document.getElementById('shade').style.setProperty('display','block', null);
  //document.getElementById('formReuniao').style.setProperty('display','block', null);
}

function createNewCategory(){
    $("#shade").fadeIn("fast");
    $("#formCategory").slideDown();
  //document.getElementById('shade').style.setProperty('display','block', null);
  //document.getElementById('formCategory').style.setProperty('display','block', null);  
}

function clearField(id) {
    obj = document.getElementById(id);
    obj.value = "";
    obj.style.setProperty('color', '#000');
}


function filterCheck(id) {
    obj = document.getElementById(id);
    if (obj.value == "") {
        if (id == "personFilter") {
            obj.value = "Pessoa";
        } else if (id == "categoryFilter") {
            obj.value = "Categoria";
        } else if (id == "projectFilter") {
            obj.value = "Projeto";
        }
    }
    
    if (obj.value != "Pessoa" && obj.value != "Categoria" && obj.value != "Projeto") {
        obj.style.setProperty('color', '#000');
    } else {
        obj.style.setProperty('color', '#c0c0c0');
    }
}
function showMessageBox(id) {
    obj = document.getElementById(id);
    
    msg = "Preencha um dos campos de filtro";
    
    box = document.getElementById("movingAlert");
    box.innerHTML = msg;
    box.style.setProperty('left',(obj.offsetLeft+125) + 'px');
    box.style.setProperty('top',(obj.offsetTop-7) + 'px');
    box.style.setProperty('display','block');
}
function hideMessageBox() {
    box = document.getElementById("movingAlert");
    box.style.setProperty('display','none');

}
function json2date(jdate){
    var date = new Date();
    date.setTime(jdate.time);
    return date.format("dd/m/yy");
}

function increasePage(month, year) {
    objMonth = document.getElementById("hiddenNextMonth");
    objYear = document.getElementById("hiddenNextYear");
    if (month == 12) {
        year++;
        month = 1;
    } else {
        month++; 
    }
    objMonth.value = month;
    objYear.value = year;
    
}
function decreasePage(month, year) {
    objMonth = document.getElementById("hiddenNextMonth");
    objYear = document.getElementById("hiddenNextYear");
    if (month == 1) {
        year--;
        month = 12;
    } else {
        month--; 
    }
    objMonth.value = month;
    objYear.value = year;
}

function loadCategories(){
    $.get('/Calendario/FindCategory', function(data) {
      var lista = eval(data);
      var resp = "";
      for(i in lista){
            resp += "<option value="+ lista[i].id + ">" + lista[i].nome + "</option>";
      }
      $("#listaCategoriasTasks").html(resp);
      $("#listaCategoriasMeetings").html(resp);
      $("#listaCategorias").html(resp);
    });
}


function newCategoryForm(){
    alert("New form");
}
function hideBlank() {
    $("#shade").hide();
    $("#tasks").hide();
    $("#form").hide();
    $("#formReuniao").hide();
    $("#formCategory").hide();
    $("#blank").fadeOut(300);
}